package mystatic.src.LT.IChoice;

import mystatic.src.LT.Book.Book;
import mystatic.src.LT.Book.BookList;

import java.util.Scanner;

public class Del implements IChoice {
    @Override
    public void work(BookList bookList) {
        System.out.println("您正在访问删除图书界面");
        System.out.println("请输入您需要删除的图书的信息：");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入书名：");
        String title = sc.nextLine();
        System.out.println("请输入本书作者：");
        String author = sc.nextLine();
        System.out.println("请输入本书类型：");
        String type = sc.nextLine();
        System.out.println("请输入本书页数：");
        int page = sc.nextInt();
        Book newBook=new Book(title,author,page,type);
        for(int i=0;i< bookList.getCnt();i++){
            Book books=bookList.getBook(i);
            if(books.getTitle().equals(title)
                    &&books.getAuthor().equals(author)
                    &&books.getType().equals(type)
                    &&books.getPages()==page
            ){
                for(int j=0;j<bookList.getCnt()-1;j++){
                    bookList.setBooks(bookList.getBook(j+1),j);
                }
                System.out.println("已删除");
                bookList.setCnt(bookList.getCnt()-1);
                return;
            }
        }
        System.out.println("未找到该书");
    }
}
